﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using SoucreGame.GLO;

namespace SoucreGame.GUI
{
    class guiManHinhThoat
    {
        
        Texture2D guiManHinhNen; // hinh anh lam nen
        Texture2D guiManhinhthoat;
        Texture2D cmdCo;
        Texture2D cmdKhong;

        Dictionary<string, Rectangle> dsToaDoGiaoDien;
        ContentManager content;
        GameTime gameTime;
        SpriteBatch spriteBatch;

        public guiManHinhThoat(ContentManager _content, GameTime _gameTime, SpriteBatch _spritBatch)
        {
            content = _content;
            gameTime = _gameTime;
            spriteBatch = _spritBatch;

            if (content != null)
            {
                guiManHinhNen = content.Load<Texture2D>("GUII\\guiManHinhNen");
                guiManhinhthoat = content.Load<Texture2D>("GUII\\guiManHinhThoat");
                cmdCo = content.Load<Texture2D>("GUII\\cmdCo");
                cmdKhong = content.Load<Texture2D>("GUII\\cmdKhong");

                dsToaDoGiaoDien = content.Load<Dictionary<string, Rectangle>>("GUII\\guiViTri");
            }
        }

        public void Update(GameTime gameTime)
        {
            CGlobalvariable.trangthaitruoc = CGlobalvariable.trangthaihientai;
            CGlobalvariable.trangthaihientai = Mouse.GetState();
            if (CGlobalvariable.trangthaihientai.LeftButton == ButtonState.Pressed && CGlobalvariable.trangthaitruoc.LeftButton == ButtonState.Released)
             {
                 if (dsToaDoGiaoDien["cmdCo"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                 {
                     CGlobalvariable.Chuyengiaodien = true;
                     CGlobalvariable.Giaodiendangchon = GUIEnum.guiThoat;
                 }

                 else if (dsToaDoGiaoDien["cmdKhong"].Contains(new Point(CGlobalvariable.trangthaihientai.X, CGlobalvariable.trangthaihientai.Y)))
                 {
                     CGlobalvariable.Chuyengiaodien = true;
                     CGlobalvariable.Giaodiendangchon = GUIEnum.guiLevel;
                 }
             }
        }

        public void Draw(GameTime gameTime)
        {
            this.spriteBatch.Draw(guiManHinhNen, Vector2.Zero, Color.White);
            this.spriteBatch.Draw(guiManhinhthoat, new Vector2(dsToaDoGiaoDien["guiManHinhThoat"].X, dsToaDoGiaoDien["guiManHinhThoat"].Y), Color.White);
            this.spriteBatch.Draw(cmdCo, new Vector2(dsToaDoGiaoDien["cmdCo"].X, dsToaDoGiaoDien["cmdCo"].Y), Color.White);
            this.spriteBatch.Draw(cmdKhong, new Vector2(dsToaDoGiaoDien["cmdKhong"].X, dsToaDoGiaoDien["cmdKhong"].Y), Color.White);
        }
    }
}
